
package com.swallowtech.mstation.common;

import java.util.Collection;

import com.swallowtech.mstation.common.domain.Entity;


public abstract class EntityUtils {

	/**
	 * Look up the entity of the given class with the given id in the given
	 * collection.
	 *
	 * @param entities the collection to search
	 * @param entityId the entity id to look up
	 * @return the found entity
	 * @throws ObjectRetrievalFailureException if the entity was not found
	 */
	public static <T extends Entity> T getById(Collection<T> entities,  int entityId)
 {
		for (T entity : entities) {
			if (entity.getId().equals(entityId)) {
				return entity;
			}
		}
		
		return null;
	}

}
